```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Java线程池深度解析 | 技术小馆</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.6;
            background-color: #f8f9fa;
        }
        .hero {
            background: linear-gradient(135deg, #6e8efb 0%, #4a6cf7 100%);
            color: white;
        }
        .code-block {
            background-color: #2d2d2d;
            color: #f8f8f2;
            border-radius: 8px;
            padding: 1.5rem;
            position: relative;
            overflow-x: auto;
        }
        .code-block::before {
            content: '';
            position: absolute;
            top: 12px;
            left: 15px;
            width: 12px;
            height: 12px;
            border-radius: 50%;
            background: #ff5f56;
            box-shadow: 20px 0 #ffbd2e, 40px 0 #27c93f;
        }
        .card {
            transition: transform 0.3s ease, box-shadow 0.3s ease;
            border-radius: 12px;
            overflow: hidden;
        }
        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
        }
        .section-title {
            position: relative;
            padding-left: 24px;
        }
        .section-title::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 8px;
            height: 24px;
            background: linear-gradient(to bottom, #4a6cf7, #6e8efb);
            border-radius: 4px;
        }
        .feature-icon {
            width: 48px;
            height: 48px;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 12px;
            margin-bottom: 16px;
        }
        .footer-links a:hover {
            opacity: 0.8;
            transform: translateX(3px);
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="hero py-20">
        <div class="container mx-auto px-6 max-w-5xl text-center">
            <div class="inline-block bg-white bg-opacity-20 px-4 py-1 rounded-full mb-6">
                <span class="text-sm font-medium">Java高并发编程</span>
            </div>
            <h1 class="text-4xl md:text-5xl font-bold mb-6">掌握ThreadPoolExecutor</h1>
            <p class="text-xl opacity-90 max-w-3xl mx-auto mb-10">线程池是Java高并发编程的核心组件，理解其原理与实现是构建高性能系统的关键</p>
            <div class="flex flex-wrap justify-center gap-4">
                <a href="#core-concept" class="px-6 py-3 bg-white text-blue-600 font-medium rounded-lg hover:bg-opacity-90 transition-all">
                    <i class="fas fa-book-open mr-2"></i>核心概念
                </a>
                <a href="#parameters" class="px-6 py-3 bg-transparent border border-white text-white font-medium rounded-lg hover:bg-white hover:bg-opacity-10 transition-all">
                    <i class="fas fa-sliders-h mr-2"></i>参数详解
                </a>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <div class="container mx-auto px-6 py-12 max-w-5xl">
        <!-- Core Concept Section -->
        <section id="core-concept" class="mb-20">
            <h2 class="text-3xl font-bold mb-8 section-title">一、ThreadPoolExecutor基础概念</h2>
            <p class="text-lg text-gray-700 mb-8 leading-relaxed">
                ThreadPoolExecutor是Java并发包中的核心类，它实现了ExecutorService接口，提供了线程池的完整实现。相比直接使用Thread，使用线程池具有显著优势，能够有效管理系统资源，提高响应速度。
            </p>
            
            <div class="grid md:grid-cols-2 gap-8 mb-12">
                <div class="card bg-white p-8 shadow-md">
                    <div class="feature-icon bg-blue-100 text-blue-600">
                        <i class="fas fa-bolt text-2xl"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-3">核心优势</h3>
                    <ul class="space-y-3">
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                            <span>降低资源消耗：复用已创建的线程</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                            <span>提高响应速度：任务到达即可执行</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                            <span>提高可管理性：统一管理线程资源</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                            <span>提供丰富功能：延时、定期执行等</span>
                        </li>
                    </ul>
                </div>
                
                <div class="card bg-white p-8 shadow-md">
                    <div class="feature-icon bg-purple-100 text-purple-600">
                        <i class="fas fa-project-diagram text-2xl"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-3">线程池生命周期</h3>
                    <div class="mermaid">
                        stateDiagram-v2
                            [*] --> RUNNING
                            RUNNING --> SHUTDOWN: shutdown()
                            RUNNING --> STOP: shutdownNow()
                            SHUTDOWN --> TIDYING: 队列空且工作线程为0
                            STOP --> TIDYING: 工作线程为0
                            TIDYING --> TERMINATED: terminated()
                    </div>
                </div>
            </div>
            
            <div class="bg-blue-50 border-l-4 border-blue-500 p-6 rounded-r-lg mb-8">
                <div class="flex">
                    <div class="flex-shrink-0">
                        <i class="fas fa-info-circle text-blue-500 text-2xl"></i>
                    </div>
                    <div class="ml-3">
                        <h3 class="text-lg font-medium text-blue-800">关键理解点</h3>
                        <div class="mt-2 text-blue-700">
                            <p>RUNNING状态时线程池能接受新任务并处理队列任务；SHUTDOWN状态不再接受新任务但会处理队列中剩余任务；STOP状态则既不接受新任务也不处理队列任务，并中断正在执行的任务。</p>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Parameters Section -->
        <section id="parameters" class="mb-20">
            <h2 class="text-3xl font-bold mb-8 section-title">二、核心参数详解</h2>
            <p class="text-lg text-gray-700 mb-8 leading-relaxed">
                ThreadPoolExecutor的完整构造函数有7个参数，这些参数共同决定了线程池的行为特征和工作方式。理解这些参数是配置适合业务场景的线程池的关键。
            </p>
            
            <div class="mb-12">
                <h3 class="text-2xl font-bold mb-6 text-gray-800">构造函数参数</h3>
                <div class="code-block mb-8">
                    <pre><code class="language-java">public ThreadPoolExecutor(int corePoolSize,
                          int maximumPoolSize,
                          long keepAliveTime,
                          TimeUnit unit,
                          BlockingQueue&lt;Runnable&gt; workQueue,
                          ThreadFactory threadFactory,
                          RejectedExecutionHandler handler)</code></pre>
                </div>
                
                <div class="grid md:grid-cols-2 gap-6">
                    <div>
                        <h4 class="text-xl font-semibold mb-4 text-gray-800">基本参数</h4>
                        <ul class="space-y-4">
                            <li>
                                <span class="font-bold text-blue-600">corePoolSize</span>: 核心线程数，线程池中始终保持的线程数量
                            </li>
                            <li>
                                <span class="font-bold text-blue-600">maximumPoolSize</span>: 最大线程数，线程池允许创建的最大线程数
                            </li>
                            <li>
                                <span class="font-bold text-blue-600">keepAliveTime</span>: 空闲线程存活时间，超过核心线程数的线程空闲时间超过该值将被回收
                            </li>
                            <li>
                                <span class="font-bold text-blue-600">unit</span>: keepAliveTime的时间单位
                            </li>
                        </ul>
                    </div>
                    <div>
                        <h4 class="text-xl font-semibold mb-4 text-gray-800">高级参数</h4>
                        <ul class="space-y-4">
                            <li>
                                <span class="font-bold text-blue-600">workQueue</span>: 工作队列，用于存放待执行的任务
                            </li>
                            <li>
                                <span class="font-bold text-blue-600">threadFactory</span>: 线程工厂，用于创建新线程
                            </li>
                            <li>
                                <span class="font-bold text-blue-600">handler</span>: 拒绝策略，当线程池和队列都满了时的处理机制
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
            
            <div class="mb-12">
                <h3 class="text-2xl font-bold mb-6 text-gray-800">工作队列类型</h3>
                <div class="grid md:grid-cols-2 lg:grid-cols-4 gap-6">
                    <div class="card bg-white p-6 shadow-sm">
                        <div class="text-purple-600 mb-3">
                            <i class="fas fa-layer-group text-2xl"></i>
                        </div>
                        <h4 class="font-bold text-lg mb-2">ArrayBlockingQueue</h4>
                        <p class="text-gray-600 text-sm">有界队列，基于数组实现的FIFO队列，适合固定大小的线程池</p>
                    </div>
                    <div class="card bg-white p-6 shadow-sm">
                        <div class="text-blue-600 mb-3">
                            <i class="fas fa-link text-2xl"></i>
                        </div>
                        <h4 class="font-bold text-lg mb-2">LinkedBlockingQueue</h4>
                        <p class="text-gray-600 text-sm">可设置容量的队列，基于链表实现，适合大多数场景</p>
                    </div>
                    <div class="card bg-white p-6 shadow-sm">
                        <div class="text-green-600 mb-3">
                            <i class="fas fa-exchange-alt text-2xl"></i>
                        </div>
                        <h4 class="font-bold text-lg mb-2">SynchronousQueue</h4>
                        <p class="text-gray-600 text-sm">不存储元素的队列，每个插入操作必须等待移除操作</p>
                    </div>
                    <div class="card bg-white p-6 shadow-sm">
                        <div class="text-red-600 mb-3">
                            <i class="fas fa-sort-amount-up-alt text-2xl"></i>
                        </div>
                        <h4 class="font-bold text-lg mb-2">PriorityBlockingQueue</h4>
                        <p class="text-gray-600 text-sm">优先级队列，根据任务的优先级执行</p>
                    </div>
                </div>
            </div>
            
            <div>
                <h3 class="text-2xl font-bold mb-6 text-gray-800">拒绝策略</h3>
                <div class="grid md:grid-cols-2 gap-6">
                    <div class="card bg-white p-6 border border-gray-200 rounded-lg">
                        <h4 class="font-bold text-lg mb-3 flex items-center">
                            <span class="bg-red-100 text-red-600 rounded-full w-6 h-6 flex items-center justify-center mr-2">1</span>
                            AbortPolicy
                        </h4>
                        <p class="text-gray-600">默认策略，直接抛出RejectedExecutionException异常</p>
                    </div>
                    <div class="card bg-white p-6 border border-gray-200 rounded-lg">
                        <h4 class="font-bold text-lg mb-3 flex items-center">
                            <span class="bg-blue-100 text-blue-600 rounded-full w-6 h-6 flex items-center justify-center mr-2">2</span>
                            CallerRunsPolicy
                        </h4>
                        <p class="text-gray-600">让提交任务的线程执行该任务</p>
                    </div>
                    <div class="card bg-white p-6 border border-gray-200 rounded-lg">
                        <h4 class="font-bold text-lg mb-3 flex items-center">
                            <span class="bg-green-100 text-green-600 rounded-full w-6 h-6 flex items-center justify-center mr-2">3</span>
                            DiscardPolicy
                        </h4>
                        <p class="text-gray-600">直接丢弃任务，不做任何处理</p>
                    </div>
                    <div class="card bg-white p-6 border border-gray-200 rounded-lg">
                        <h4 class="font-bold text-lg mb-3 flex items-center">
                            <span class="bg-purple-100 text-purple-600 rounded-full w-6 h-6 flex items-center justify-center mr-2">4</span>
                            DiscardOldestPolicy
                        </h4>
                        <p class="text-gray-600">丢弃队列最前面的任务，然后重新提交当前任务</p>
                    </div>
                </div>
            </div>
        </section>

        <!-- Working Principle Section -->
        <section class="mb-20">
            <h2 class="text-3xl font-bold mb-8 section-title">三、线程池工作原理</h2>
            <p class="text-lg text-gray-700 mb-8 leading-relaxed">
                ThreadPoolExecutor执行任务遵循特定的处理流程，理解这一流程对于正确配置线程池参数和排查问题至关重要。
            </p>
            
            <div class="bg-white rounded-xl shadow-md overflow-hidden mb-8">
                <div class="p-6">
                    <div class="mermaid">
                        graph TD
                            A[提交任务] --> B{当前线程数 < corePoolSize?}
                            B -->|是| C[创建新线程执行任务]
                            B -->|否| D{工作队列未满?}
                            D -->|是| E[任务入队等待]
                            D -->|否| F{当前线程数 < maximumPoolSize?}
                            F -->|是| G[创建新线程执行任务]
                            F -->|否| H[执行拒绝策略]
                    </div>
                </div>
            </div>
            
            <div class="code-block mb-8">
                <pre><code class="language-java">public void execute(Runnable command) {
    if (command == null)
        throw new NullPointerException();
    
    int c = ctl.get();
    // 如果运行的线程数小于核心线程数
    if (workerCountOf(c) &lt; corePoolSize) {
        // 创建新线程执行任务
        if (addWorker(command, true))
            return;
        c = ctl.get();
    }
    // 如果线程池处于运行状态且任务成功加入队列
    if (isRunning(c) &amp;&amp; workQueue.offer(command)) {
        int recheck = ctl.get();
        // 二次检查：如果线程池已停止，从队列移除任务并拒绝
        if (!isRunning(recheck) &amp;&amp; remove(command))
            reject(command);
        // 如果没有工作线程，添加一个
        else if (workerCountOf(recheck) == 0)
            addWorker(null, false);
    }
    // 队列已满，尝试创建新线程
    else if (!addWorker(command, false))
        // 创建失败，执行拒绝策略
        reject(command);
}</code></pre>
            </div>
            
            <div class="bg-yellow-50 border-l-4 border-yellow-400 p-6 rounded-r-lg">
                <div class="flex">
                    <div class="flex-shrink-0">
                        <i class="fas fa-lightbulb text-yellow-500 text-2xl"></i>
                    </div>
                    <div class="ml-3">
                        <h3 class="text-lg font-medium text-yellow-800">执行流程要点</h3>
                        <div class="mt-2 text-yellow-700">
                            <p>1. 优先使用核心线程 → 2. 任务入队等待 → 3. 创建临时线程 → 4. 拒绝策略</p>
                            <p class="mt-2">注意工作队列的选择会直接影响线程池行为：有界队列有助于防止资源耗尽，但需要合理设置队列大小和拒绝策略。</p>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Practical Examples Section -->
        <section class="mb-20">
            <h2 class="text-3xl font-bold mb-8 section-title">四、实战应用案例</h2>
            <p class="text-lg text-gray-700 mb-8 leading-relaxed">
                通过实际代码示例展示ThreadPoolExecutor在不同场景下的应用方式，从基础使用到高级配置。
            </p>
            
            <div class="space-y-12">
                <!-- Example 1 -->
                <div>
                    <h3 class="text-2xl font-bold mb-6 text-gray-800">1. 自定义线程池</h3>
                    <div class="code-block">
                        <pre><code class="language-java">// 创建自定义线程工厂
ThreadFactory namedThreadFactory = new ThreadFactory() {
    private final AtomicInteger threadNumber = new AtomicInteger(1);
    
    @Override
    public Thread newThread(Runnable r) {
        Thread t = new Thread(r, "custom-thread-" + threadNumber.getAndIncrement());
        if (t.isDaemon()) t.setDaemon(false);
        if (t.getPriority() != Thread.NORM_PRIORITY) {
            t.setPriority(Thread.NORM_PRIORITY);
        }
        return t;
    }
};

// 创建自定义线程池
ThreadPoolExecutor executor = new ThreadPoolExecutor(
    5,                       // 核心线程数
    10,                      // 最大线程数
    60L,                     // 空闲线程存活时间
    TimeUnit.SECONDS,        // 时间单位
    new LinkedBlockingQueue<>(100), // 工作队列
    namedThreadFactory,      // 线程工厂
    new ThreadPoolExecutor.CallerRunsPolicy() // 拒绝策略
);

// 提交任务
for (int i = 0; i &lt; 50; i++) {
    executor.execute(() -> {
        System.out.println(Thread.currentThread().getName() + " 执行任务");
        try { Thread.sleep(500); } catch (InterruptedException e) { ... }
    });
}

// 优雅关闭线程池
executor.shutdown();
try {
    if (!executor.awaitTermination(30, TimeUnit.SECONDS)) {
        executor.shutdownNow();
    }
} catch (InterruptedException e) {
    executor.shutdownNow();
}</code></pre>
                    </div>
                </div>
                
                <!-- Example 2 -->
                <div>
                    <h3 class="text-2xl font-bold mb-6 text-gray-800">2. 使用Future获取异步任务结果</h3>
                    <div class="code-block">
                        <pre><code class="language-java">ExecutorService executor = Executors.newFixedThreadPool(5);
List&lt;Future&lt;Integer&gt;&gt; futures = new ArrayList&lt;&gt;();

// 提交10个计算任务
for (int i = 0; i &lt; 10; i++) {
    final int taskId = i;
    Future&lt;Integer&gt; future = executor.submit(() -> {
        Thread.sleep(1000); // 模拟耗时计算
        return taskId * 100;
    });
    futures.add(future);
}

// 获取计算结果
futures.forEach(future -> {
    try {
        Integer result = future.get(2, TimeUnit.SECONDS);
        System.out.println("任务结果: " + result);
    } catch (InterruptedException | ExecutionException | TimeoutException e) {
        // 异常处理
    }
});

executor.shutdown();</code></pre>
                    </div>
                </div>
                
                <!-- Example 3 -->
                <div>
                    <h3 class="text-2xl font-bold mb-6 text-gray-800">3. 定时任务与周期性任务</h3>
                    <div class="code-block">
                        <pre><code class="language-java">ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(2);

// 延迟3秒后执行的任务
scheduler.schedule(() -> {
    System.out.println("延迟任务执行");
}, 3, TimeUnit.SECONDS);

// 延迟2秒后，每5秒执行一次的周期任务
scheduler.scheduleAtFixedRate(() -> {
    System.out.println("固定速率任务执行");
    try { Thread.sleep(2000); } catch (InterruptedException e) { ... }
}, 2, 5, TimeUnit.SECONDS);

// 延迟2秒后，上一次执行完毕后再等待3秒执行下一次的任务
scheduler.scheduleWithFixedDelay(() -> {
    System.out.println("固定延迟任务执行");
    try { Thread.sleep(1000); } catch (InterruptedException e) { ... }
}, 2, 3, TimeUnit.SECONDS);

// 主线程休眠，让定时任务能够执行
try { Thread.sleep(30000); } catch (InterruptedException e) { ... }

scheduler.shutdown();</code></pre>
                    </div>
                </div>
            </div>
        </section>

        <!-- Performance Tuning Section -->
        <section class="mb-20">
            <h2 class="text-3xl font-bold mb-8 section-title">五、线程池源码解析与性能调优</h2>
            <p class="text-lg text-gray-700 mb-8 leading-relaxed">
                深入理解ThreadPoolExecutor的内部实现机制，并掌握如何根据实际业务场景优化线程池配置。
            </p>
            
            <div class="grid md:grid-cols-2 gap-8 mb-12">
                <div>
                    <h3 class="text-2xl font-bold mb-6 text-gray-800">Worker线程源码解析</h3>
                    <div class="code-block">
                        <pre><code class="language-java">private final class Worker extends AbstractQueuedSynchronizer implements Runnable {
    final Thread thread;
    Runnable firstTask;
    
    Worker(Runnable firstTask) {
        setState(-1); // 禁止在运行任务时中断
        this.firstTask = firstTask;
        this.thread = getThreadFactory().newThread(this);
    }
    
    public void run() {
        runWorker(this);
    }
}

final void runWorker(Worker w) {
    Thread wt = Thread.currentThread();
    Runnable task = w.firstTask;
    w.firstTask = null;
    w.unlock(); // 允许中断
    
    boolean completedAbruptly = true;
    try {
        while (task != null || (task = getTask()) != null) {
            w.lock();
            // 线程池关闭相关检查...
            try {
                beforeExecute(wt, task);
                try {
                    task.run();
                    afterExecute(task, null);
                } catch (Throwable ex) {
                    afterExecute(task, ex);
                    throw ex;
                }
            } finally {
                task = null;
                w.completedTasks++;
                w.unlock();
            }
        }
        completedAbruptly = false;
    } finally {
        processWorkerExit(w, completedAbruptly);
    }
}</code></pre>
                    </div>
                </div>
                
                <div>
                    <h3 class="text-2xl font-bold mb-6 text-gray-800">性能调优建议</h3>
                    <div class="space-y-6">
                        <div class="bg-white p-6 rounded-lg shadow-sm">
                            <h4 class="font-bold text-lg mb-3 flex items-center text-blue-600">
                                <i class="fas fa-microchip mr-2"></i>核心线程数设置
                            </h4>
                            <div class="code-block-sm bg-gray-100 p-4 rounded">
                                <pre><code class="language-java">// 获取CPU核心数
int processors = Runtime.getRuntime().availableProcessors();

// 计算密集型任务
int corePoolSize = processors + 1;

// I/O密集型任务 (假设I/O等待时间是计算时间的8倍)
int ioIntensiveCoreSize = processors * (1 + 8);</code></pre>
                            </div>
                        </div>
                        
                        <div class="bg-white p-6 rounded-lg shadow-sm">
                            <h4 class="font-bold text-lg mb-3 flex items-center text-purple-600">
                                <i class="fas fa-tasks mr-2"></i>队列选择策略
                            </h4>
                            <ul class="space-y-3">
                                <li class="flex items-start">
                                    <i class="fas fa-circle text-xs mt-2 mr-2 text-purple-500"></i>
                                    <span><span class="font-semibold">短任务、高并发</span>: SynchronousQueue</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-circle text-xs mt-2 mr-2 text-purple-500"></i>
                                    <span><span class="font-semibold">长任务、低并发</span>: LinkedBlockingQueue</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-circle text-xs mt-2 mr-2 text-purple-500"></i>
                                    <span><span class="font-semibold">需要控制并发量</span>: ArrayBlockingQueue</span>
                                </li>
                            </ul>
                        </div>
                        
                        <div class="bg-white p-6 rounded-lg shadow-sm">
                            <h4 class="font-bold text-lg mb-3 flex items-center text-green-600">
                                <i class="fas fa-shield-alt mr-2"></i>拒绝策略选择
                            </h4>
                            <ul class="space-y-3">
                                <li class="flex items-start">
                                    <i class="fas fa-circle text-xs mt-2 mr-2 text-green-500"></i>
                                    <span><span class="font-semibold">重要任务</span>: CallerRunsPolicy</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-circle text-xs mt-2 mr-2 text-green-500"></i>
                                    <span><span class="font-semibold">可丢弃任务</span>: DiscardPolicy/DiscardOldestPolicy</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-circle text-xs mt-2 mr-2 text-green-500"></i>
                                    <span><span class="font-semibold">需要异常提醒</span>: AbortPolicy</span>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
            
            <div>
                <h3 class="text-2xl font-bold mb-6 text-gray-800">线程池监控示例</h3>
                <div class="code-block">
                    <pre><code class="language-java">public class ThreadPoolMonitor {
    public static void monitorThreadPool(ThreadPoolExecutor pool) {
        ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
        scheduler.scheduleAtFixedRate(() -> {
            System.out.println("====== 线程池状态 ======");
            System.out.println("核心线程数: " + pool.getCorePoolSize());
            System.out.println("活动线程数: " + pool.getActiveCount());
            System.out.println("最大线程数: " + pool.getMaximumPoolSize());
            System.out.println("线程池大小: " + pool.getPoolSize());
            System.out.println("任务队列大小: " + pool.getQueue().size());
            System.out.println("已完成任务数: " + pool.getCompletedTaskCount());
            System.out.println("总任务数: " + pool.getTaskCount());
            System.out.println("======================");
        }, 0, 5, TimeUnit.SECONDS);
    }
}</code></pre>
                </div>
            </div>
        </section>
    </div>

    <!-- Footer -->
    <footer class="bg-gray-900 text-white py-12">
        <div class="container mx-auto px-6 max-w-5xl">
            <div class="flex flex-col md:flex-row justify-between items-center">
                <div class="mb-6 md:mb-0">
                    <h3 class="text-2xl font-bold">技术小馆</h3>
                    <p class="text-gray-400 mt-2">专注技术分享与知识传播</p>
                </div>
                <div class="footer-links">
                    <a href="http://www.yuque.com/jtostring" class="flex items-center text-gray-300 hover:text-white transition-colors">
                        <i class="fas fa-globe mr-2"></i> 访问语雀主页
                    </a>
                </div>
            </div>
            <div class="border-t border-gray-800 mt-8 pt-8 text-center text-gray-400 text-sm">
                <p>© 2023 技术小馆. 保留所有权利.</p>
            </div>
        </div>
    </footer>

    <script>
        // Initialize Mermaid
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });
        
        // Smooth scrolling for anchor links
        document.querySelectorAll('a[href^="#"]').forEach(anchor => {
            anchor.addEventListener('click', function (e) {
                e.preventDefault();
                document.querySelector(this.getAttribute('href')).scrollIntoView({
                    behavior: 'smooth'
                });
            });
        });
    </script>
</body>
</html>
```